import {User} from '../models/user';
import {Injectable} from 'angular2/core';
import {Photo} from '../models/photo';
import {Http, Headers} from 'angular2/http';
import { TaskInfo } from '../models/taskInfo';
import {ShareTask} from '../models/sharedtask';

@Injectable()
export class TaskService {

  constructor (private http : Http) {}

  getTasksByUser(user: User) {
    let url="http://localhost:5000/api/task/user";
    let header = new Headers ({'Content-Type' : 'application/json', 'Authorization': 'Bearer '+localStorage.getItem("token")});

    return this.http.post(url, JSON.stringify(user), {headers: header});
  }

  getTaskInfoById(taskId: number) {
    let url="http://localhost:5000/api/task/taskId";
    let header = new Headers ({'Content-Type' : 'application/json', 'Authorization': 'Bearer '+localStorage.getItem("token")});
    let data={"TaskId":taskId};
    return this.http.post(url, JSON.stringify(data), {headers: header});
  }

  updateTask(taskInfo: TaskInfo) {
    let url="http://localhost:5000/api/task/update";
    let header = new Headers ({'Content-Type' : 'application/json', 'Authorization': 'Bearer '+localStorage.getItem("token")});

    return this.http.post(url, JSON.stringify(taskInfo), {headers: header});
  }

  getSharedTasks(user: User) {
    let url="http://localhost:5000/api/task/shared";
    let header = new Headers ({'Content-Type' : 'application/json', 'Authorization': 'Bearer '+localStorage.getItem("token")});

    return this.http.post(url, JSON.stringify(user), {headers: header});
  }

  sharedTasks(sharedTasks:ShareTask[]){
    let url="http://localhost:5000/api/task/sharedtasks";
    let header = new Headers ({'Content-Type' : 'application/json', 'Authorization': 'Bearer '+localStorage.getItem("token")});

    return this.http.post(url, JSON.stringify(sharedTasks), {headers: header});

  }

}
